<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>函数作为返回值</title>
  </head>
  <body>
    <script>
      /*
         函数作为返回值
        */
      function makeFn(params) {
        let msg = "caozy";
        return function () {
          console.log(msg);
        };
      }
      const fn = makeFn();
      fn();
      //手写once 控制函数只执行一次
      function once(fn) {
        let done = false;
        return function () {
          if (!done) {
            done = true;
            return fn.apply(this, arguments);
          }
        };
      }
      let pay = once(function (money) {
        console.log("支付：" + money);
      });
      pay(5);
      pay(5);
      pay(5);
      pay(5);
    </script>
  </body>
</html>
